92d0b8
@@ -84,6 +84,7 @@
 import org.apache.hadoop.hive.shims.Utils;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hadoop.util.ReflectionUtils;
+import org.apache.hadoop.util.Shell;
 
 import com.google.common.base.Preconditions;
 
@@ -1160,7 +1161,7 @@
public String add_resource(ResourceType t, String value, boolean convertToUnix)
 
         if (getURLType(value).equals("ivy")) {
           // get the key to store in map
-          key = new URI(value).getAuthority();
+          key = createURI(value).getAuthority();
         } else {
           // for local file and hdfs, key and value are same.
           key = downloadedURLs.get(0).toString();
@@ -1201,8 +1202,22 @@
public String add_resource(ResourceType t, String value, boolean convertToUnix)
     return localized;
   }
 
+  /**
+   * @param path
+   * @return URI corresponding to the path.
+   */
+  private static URI createURI(String path) throws URISyntaxException {
+    if (!Shell.WINDOWS) {
+      // If this is not windows shell, path better follow unix convention.
+      // Else, the below call will throw an URISyntaxException
+      return new URI(path);
+    } else {
+      return new Path(path).toUri();
+    }
+  }
+
   private static String getURLType(String value) throws URISyntaxException {
-    URI uri = new URI(value);
+    URI uri = createURI(value);
     String scheme = uri.getScheme() == null ? null : uri.getScheme().toLowerCase();
     if (scheme == null || scheme.equals("file")) {
       return "file";
@@ -1215,13 +1230,13 @@
private static String getURLType(String value) throws URISyntaxException {
 
   List<URI> resolveAndDownload(ResourceType t, String value, boolean convertToUnix) throws URISyntaxException,
       IOException {
-    URI uri = new URI(value);
+    URI uri = createURI(value);
     if (getURLType(value).equals("file")) {
       return Arrays.asList(uri);
     } else if (getURLType(value).equals("ivy")) {
       return dependencyResolver.downloadDependencies(uri);
     } else if (getURLType(value).equals("hdfs")) {
-      return Arrays.asList(new URI(downloadResource(value, convertToUnix)));
+      return Arrays.asList(createURI(downloadResource(value, convertToUnix)));
     } else {
       throw new RuntimeException("Invalid url " + uri);
     }
@@ -1252,7 +1267,7 @@
private String downloadResource(String value, boolean convertToUnix) {
         throw new RuntimeException("Couldn't create directory " + resourceDir);
       }
       try {
-        FileSystem fs = FileSystem.get(new URI(value), conf);
+        FileSystem fs = FileSystem.get(createURI(value), conf);
         fs.copyToLocalFile(new Path(value), new Path(destinationFile.getCanonicalPath()));
         value = destinationFile.getCanonicalPath();
 
@@ -1286,7 +1301,7 @@
public void delete_resources(ResourceType t, List<String> values) {
       String key = value;
       try {
         if (getURLType(value).equals("ivy")) {
-          key = new URI(value).getAuthority();
+          key = createURI(value).getAuthority();
         }
       } catch (URISyntaxException e) {
         throw new RuntimeException("Invalid uri string " + value + ", " + e.getMessage());
